package com.land.study.intent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class IntentStudyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	SLog.d("IntentStudyActivity onCreate");
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        
        final EditText txt = (EditText) findViewById(R.id.txt_send_intent);
        final Button btn = (Button) findViewById(R.id.btn_send_intent);
        final Button btnSendIntentAnotherApp = (Button) findViewById(R.id.btn_send_intent_another_app);
        final CheckBox chkUseParcelable = (CheckBox) findViewById(R.id.chk_use_parcelable);
        
        btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SLog.d("start another Activity");
				
				Intent intent = new Intent("com.land.study.intent.receiveintent");
				
        		if (chkUseParcelable.isChecked()) {
        			SLog.d("using parcelable");
        			ParcelableVO vo = new ParcelableVO();
        			vo.setTxt(txt.getText().toString());
        			
        			intent.putExtra(ReceiveActivity.INTENT_EXTRA_KEY, vo);
        		} else {
        			SLog.d("using intent extra string");
        			intent.putExtra(ReceiveActivity.INTENT_EXTRA_KEY, txt.getText().toString());
        		}
				
        		startActivity(intent);
			}
		});
        
        btnSendIntentAnotherApp.setOnClickListener(new OnClickListener() {
        	
        	@Override
        	public void onClick(View v) {
        		SLog.d("start another Activity");
        		Intent intent = new Intent("com.land.study.intentreceiver.receive");
        		
        		if (chkUseParcelable.isChecked()) {
        			SLog.d("using parcelable");
        			ParcelableVO vo = new ParcelableVO();
        			vo.setTxt(txt.getText().toString());
        			
        			intent.putExtra(ReceiveActivity.INTENT_EXTRA_KEY, vo);
        		} else {
        			SLog.d("using intent extra string");
        			intent.putExtra(ReceiveActivity.INTENT_EXTRA_KEY, txt.getText().toString());
        		}
        		
        		startActivity(intent);
        	}
        });
    }
}
